package change

import (
	"AES/GF"
)

var col_s = [][]byte{
	{2, 3, 1, 1},
	{1, 2, 3, 1},
	{1, 1, 2, 3},
	{3, 1, 1, 2},
}

var re_col_s = [][]byte {
	{14, 11, 13, 9},
	{9, 14, 11, 13},
	{13, 9, 14, 11},
	{11, 13, 9, 14},
}

func Col_Change(p *[][]byte) [][]byte {
	re := make([][]byte, 4)
	for j := 0; j < 4; j++ {
		re[j] = make([]byte, 4)
	}
	for i := 0; i < 4; i++ {
		for j := 0; j < 4; j++ {
			tmp := byte(0)
			for k := 0; k < 4; k++ {
				tmp ^= GF.Multiply(col_s[i][k], (*p)[k][j])
			}
			re[i][j] = tmp
		}
	}
	return re
}

func Re_Colchange(p *[][]byte) [][]byte {
	re := make([][]byte, 4)
	for j := 0; j < 4; j++ {
		re[j] = make([]byte, 4)
	}
	for i := 0; i < 4; i++ {
		for j := 0; j < 4; j++ {
			tmp := byte(0)
			for k := 0; k < 4; k++ {
				tmp ^= GF.Multiply(re_col_s[i][k], (*p)[k][j])
			}
			re[i][j] = tmp
		}
	}
	return re
}
